package cn.wolfcode.domain;

import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
public class SystemDictionaryItem {
    private Long id;

    private String title;

    private Integer sequence;

    private SystemDictionary type;

    private SystemDictionaryItem parent;

    public String toJson(){
        HashMap<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("title", title);
        map.put("sequence", sequence);
        //当修改的字典明细的type没有时，则不需要
        if (type != null){
            map.put("typeId", type.getId());
        }
        //当修改的字典明细的parent没有时，则不需要
        //为不为空时，则拿取parent的title设值回去，不然页面option拿不到
        if (parent != null){
            map.put("parentTitle", parent.getTitle());
            map.put("parentId", parent.getId());
        }
        return JSON.toJSONString(map);
    }


}